import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getx_example/get_connect_dio/controller/my_get_connect_dio_controller.dart';

class MyGetConnectDioPage extends GetView<MyGetConnectDioController> {

  static const String route = "/MyGetConnectDioPage";

  const MyGetConnectDioPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Get Connect Dio'),
      ),
      body: Obx(() => Column(
            children: [
              ElevatedButton(
                onPressed: () {
                  controller.getData();
                },
                child: const Text('Get Data'),
              ),
              controller.dataList.value.isEmpty
                  ? const CircularProgressIndicator()
                  : Expanded(
                      child: ListView.builder(
                        itemCount: controller.dataList.value.length,
                        itemBuilder: (context, index) {
                          return ListTile(
                            title: Text(controller.dataList.value[index].title),
                            subtitle: Text(controller.dataList.value[index].body),
                          );
                        },
                      ),
                    ),
            ],
          )),
    );
  }
}
